package com.sk.skplanet.commute.views;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.os.Bundle;
import android.os.StrictMode;
import android.view.Menu;
import android.widget.LinearLayout;
import android.widget.Toast;

import com.sk.skplanet.commute.R;
import com.sk.skplanet.commute.actions.LoadingTask;
import com.sk.skplanet.commute.actions.Temp;
import com.sk.skplanet.commute.controllers.RouteController;
import com.sk.skplanet.commute.dao.RouteDao;
import com.sk.skplanet.commute.vo.RouteVo;

public class RouteList extends Activity {

	LinearLayout layout_locationlist;
	List<RouteVo> list;
	List<Temp> temp_list;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.routelist);

		StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectDiskReads().detectDiskWrites()
				.detectNetwork().penaltyLog().build());

		layout_locationlist = (LinearLayout) findViewById(R.id.layout_locationlist);

		
		
		list = RouteDao.selectRoute();
		if (list != null) {
			for (RouteVo r : list)
				layout_locationlist.addView(RouteController.makeRoute(this, r));
		}
		temp_list = new ArrayList<Temp>();
		// new LoadingTask(this, "우군", temp_list);

		// nameValue.add(new BasicNameValuePair("name", email));
		try {
			// HttpClient httpclient = new DefaultHttpClient();
			// // Vector<NameValuePair> nameValue = new Vector<NameValuePair>();
			// HttpGet httppost = new HttpGet(Data.URL);
			// HttpResponse responseGet = httpclient.execute(httppost);
			// HttpEntity resEntityGet = responseGet.getEntity();
			// Log.i("test123", EntityUtils.toString(resEntityGet));

			// httppost.setEntity(new UrlEncodedFormEntity(nameValue,
			// HTTP.UTF_8));
			// InputStream is =
			// httpclient.execute(httppost).getEntity().getContent();
			// BufferedReader reader = new BufferedReader(new
			// InputStreamReader(is, "UTF-8"));
			// StringBuilder sb = new StringBuilder();
			// String line = null;
			// while ((line = reader.readLine()) != null)
			// sb.append(line + "\n");
			// is.close();
			// temp_list.clear();
			// Log.i("test123", sb.toString());
			// Toast.makeText(this, sb.toString(), Toast.LENGTH_SHORT).show();
			// JSONArray jArray = new JSONArray(sb.toString());

			// for (int i = 0; i < jArray.length(); i++) {
			// Toast.makeText(this, i, Toast.LENGTH_SHORT).show();
			// JSONObject json_data = jArray.getJSONObject(i);
			// Temp data = new Temp(json_data.getInt("id"),
			// json_data.getString("name"));
			// temp_list.add(data);
			// }
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		new LoadingTask(this, "우군", temp_list).execute();

//		Toast.makeText(this, temp_list.get(0).getName(), Toast.LENGTH_SHORT).show();

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

}
